<template>
	<view style="display: flex;flex-direction: column;width: 100%;height: 100%;position: relative;">
		<view class="top bg_fff pd-20">
			<u-image :src="data.cover" width="130rpx" height="130rpx"></u-image>
			<view class="itemBase f_28">
				<text class="c_333333 title">{{data.name||""}}</text>
				<view class="mt-8">
					<text class="c_999999 set_type">{{data.settlement_type.settlement_type_text||""}}</text>
					<text class="c_C62B2C ml-10" v-if="data.commission>0">￥{{data.commission||"0"}}</text>
				</view>
				<view class="c_999999 mt-8">截至时间：{{data.end_time.end_time_text||"长期有效"}}</view>
			</view>
		</view>

		<view style="margin-bottom: 120rpx;margin-top: 20rpx;background-color: #fff;padding: 10rpx 20rpx;">
			<u-parse :content="data.content"></u-parse>
		</view>

		<view class="btmBox c_ffffff" @click="goNext" v-if="userInfo!=null&&showBtn">
			接受任务
		</view>
	</view>
</template>

<script>
	import {
		posJointMission
	} from '@/config/api.js'

	export default {
		name: "mission_detail",
		props: {
			data: {
				type: Object,
				default: null,
			},
			showBtn: {
				type: Boolean,
				default: true,
			}
		},
		data() {
			return {
				userInfo: null
			};
		},
		created() {
			this.userInfo = uni.getStorageSync('UserInfo');
		},
		methods: {
			goNext() {

				if (this.userInfo.username == "" || this.userInfo.headimg == "" || this.userInfo.phone == "") {
					uni.showModal({
						title: '提示',
						content: '未完善信息',
						confirmText: '完善',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/center/info"
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})

					return;
				}

				posJointMission({
					mission_id: this.data.id,
					user_id: this.userInfo.id
				}).then(res => {
					uni.showToast({
						title: "操作成功",
						icon: 'success',
						duration: 2000
					})
					this.$emit("success");
				}).catch(err => {
					uni.showToast({
						icon: 'none',
						title: err.info,
						duration: 2000
					});
				})
			}
		}
	}
</script>

<style scoped>
	.top {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.itemBase {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		margin-left: 20rpx;
	}

	.set_type {
		border: 1px solid #999;
		border-radius: 6rpx;
		padding: 2rpx 4rpx;
		text-align: center;
		width: 120rpx;
	}

	.title {
		font-size: 36rpx;
		font-weight: 600;
	}

	.btmBox {
		background: linear-gradient(to bottom, #C62B2C, #FF7C71);
		border-radius: 40rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 40rpx;
		font-weight: 600;
		box-sizing: border-box;
		margin-left: 5%;
		width: 90%;

		position: fixed;
		bottom: 20rpx;
	}
</style>
